<?php
$startTimeStr = Yii::t('BWeSport', 'Start Time');
$timeLengthStr = Yii::t('BWeSport', 'Time Length');
$splitTimesStr = Yii::t('BWeSport', 'Split Times');
$repeatTypeStr = Yii::t('BWeSport', 'Repeat Type');
$operateStr = Yii::t('BWeSport', 'Operate');
$modifyStr = Yii::t('BWeSport', 'Modify');
$addTimeSlotStr = Yii::t('BWeSport', 'Add TimeSlot');
$deleteStr = Yii::t('BWeSport', 'Delete');
$app = Blyn::app()->getActiveApp();
$event = new BWEvent($eventId);
$vender = $event->getMessageManager()->getMessage('vender');
$bookableMessage = new BWMessage($bookableId);
$timeSlotInputMedia = $bookableMessage->getInputMediaManager()->getInputMedia('timeSlot');
$timeSlotConfigList = array();
if ($timeSlotInputMedia instanceof BWInputMedia) {
    $inputType = $timeSlotInputMedia->getInputType();
    $timeSlotConfigList = $timeSlotInputMedia->getMessageManager()->getMessageList();
} else {
    $timeSlotInputMedia = new BWInputMedia($bookableMessage);
    $timeSlotInputMedia->name = 'timeSlot';
    $timeSlotInputMedia->save();
    $timeSlotInputMedia->setInputType(new BWTimeSlotType());
    $bookableMessage->getInputMediaManager()->addInputMedia($timeSlotInputMedia);
}
?>
<link rel="stylesheet" type="text/css"
      href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap-datetimepicker.min.css" />
<script  type="text/javascript"
         src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-datetimepicker.min.js"/>

<script type="text/javascript">
    $(document).ready(function() {
        $("#selectAll").click(function() {
            if ($(this).attr("checked") == "checked") {
                $(":checkbox").attr("checked", true);
            } else {
                $(":checkbox").attr("checked", false);
            }
        });

    });
</script> 
<script type="text/javascript">
    $(function() {
        $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
        $('.tree li.parent_li > span').on('click', function(e) {
            var children = $(this).parent('li.parent_li').find(' > ul > li');
            if (children.is(":visible")) {
                children.hide('fast');
                $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
            } else {
                children.show('fast');
                $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            }
            e.stopPropagation();
        });
    });</script>
<script type="text/javascript">
    $(function() {
        $("#Event_Shop_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = '';
            document.getElementById("Event_Clothes_CX_View").style.display = 'none';
        });
        $("#Event_Clothes_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = 'none';
            document.getElementById("Event_Clothes_CX_View").style.display = '';
        });
    });
</script>

<fieldset>
    <table class="table table-hover">
        <thead>
            <tr>
                <th>
                    <input type="checkbox"  id="selectAll"> 
                </th>
                <th><?php echo $startTimeStr; ?></th>
                <th><?php echo $timeLengthStr; ?></th>
                <th><?php echo $splitTimesStr; ?></th>   
                <th><?php echo $repeatTypeStr; ?></th>
                <th><?php echo $operateStr; ?></th>
            </tr> 
        </thead>
        <tbody>
            <?php
            foreach ($timeSlotConfigList as $id => $timeSlotConfig) {
                $length = $timeSlotConfig->getMediaManager()->getMedia('length')->getContent();
                $timeUnit = $timeSlotConfig->getMediaManager()->getMedia('lengthUnit')->getContent();
                ?>
                <tr>
                    <td><label class="checkbox">
                            <input type="checkbox" name="checkbox[]" value="<?php echo $id; ?>"> 
                        </label></td>
                    <td> <?php echo $timeSlotConfig->getMediaManager()->getMedia('startTime')->getContent(); ?> </td>

                    <td> <?php echo $length . ' ' .  Yii::t('BWeSport', $timeUnit) ?> </td>
                    <td> <?php echo $timeSlotConfig->getMediaManager()->getMedia('splitTimes')->getContent(); ?> </td>
                    <td> <?php echo  Yii::t('BWeSport', $timeSlotConfig->getMediaManager()->getMedia('repeatType')->getContent()); ?> </td>
                    <td>
                        <div class="row-fluid">                         
                            <?php
                            echo $control->getAjaxLink(array('name' => $modifyStr, 'id' => 'showAddTimeSlot'), array(
                                'eventId' => $eventId,
                                'bookableId' => $bookableId,
                                'timeSlotId' => $id,
                                'ajaxContainerId' => 'myModal2',
                                'htmlOptions' => array(
                                    'enctype' => 'multipart/form-data'),
                                'ajaxOptions' => array(
                                    'complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal2").modal("show");}')
                            ));
                            ?> 
                            <?PHP echo " | "; ?>
                            <?php
                            echo $control->getAjaxLink(array('name' => '删除', 'id' => 'deleteTimeSlot'), array(
                                'eventId' => $eventId,
                                'bookableId' => $bookableId,
                                'timeSlotId' => $id,
                            ));
                            ?>
                        </div>                      
                    </td>
                </tr>
            <?php } ?>
        </tbody>
    </table>

    <div class="row-fluid">
        <?php
        echo $control->getAjaxLink(array('name' => $addTimeSlotStr, 'id' => 'showAddTimeSlot'), array(
            'eventId' => $eventId,
            'bookableId' => $bookableId,
            'timeSlotId' => 0,
            'ajaxContainerId' => 'myModal2',
            'htmlOptions' => array(
                'enctype' => 'multipart/form-data',
                'class' => 'btn'),
            'ajaxOptions' => array(
                'complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal2").modal("show");}'
            ),
        ));
        ?>
        <?php
        echo $control->getAjaxLink(array('name' => $deleteStr, 'id' => 'deleteCheckedTimeSlot'), array(
            'htmlOptions' => array(
                'class' => 'btn',
                'enctype' => 'multipart/form-data'), 
            'eventId' => $eventId,
            'bookableId' => $bookableId
                            ));
        ?>
    </div>   
    <div id="myModal2" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    </div>

    <div><input type="hidden" name="curPageNo" value="1"></div>

    <div class="pagination">  
        <ul>  
            <li class="active">
                <a href="javascript:void()">前一页</a>    </li>  
            <li class="active">
                <a href="javascript:void()">1</a>    </li>  
            <li class="active">
                <a href="javascript:void()">后一页</a>    </li>  
        </ul>  
    </div>


